#include<iostream>
#include<cstring>
#include<queue>
using namespace std;
int maze[5][5];
bool inRange(int x,int y){
    return (x>=0&&x<5&&y>=0&&y<5);
}
struct Pos{
    int r,c;
    vector<Pos> v;
};
Pos start,goal;
struct Dir{
    int r,c;
}dir[4]={{1,0},{-1,0},{0,1},{0,-1}};
int visited[5][5];
queue<Pos> q;
int main(){
    memset(visited,0,sizeof(visited));
    while(!q.empty()) q.pop();
    for(int i=0;i<5;i++)
    for(int j=0;j<5;j++)
        cin>>maze[i][j];
    start.r=0;start.c=0;start.v.push_back(start);
    goal.r=4,goal.c=4;
    visited[start.r][start.c]=1;
    q.push(start);
    Pos p;
    while(!q.empty()){
        p=q.front();
        if(p.r==goal.r&&p.c==goal.c){
            for(int i=0;i<p.v.size();i++){
                cout<<"("<<p.v[i].r<<", "<<p.v[i].c<<")"<<endl;
            }
            return 0;
        }
        q.pop();
        
        int nr,nc;
        for(int i=0;i<4;i++){
            nr=p.r+dir[i].r;
            nc=p.c+dir[i].c;
            if(inRange(nr,nc)&&visited[nr][nc]==0&&maze[nr][nc]==0){
                visited[nr][nc]=1;
                Pos temp;
                temp.r=nr,temp.c=nc,temp.v=p.v;temp.v.push_back(temp);
                q.push(temp);
            }
        }

    }
    
    
    return 0;
}

